import React from 'react'
import { LazyImageType } from '../image/PropsType'
import { PopupCloseIconPosition } from '../popup/PropsType'
import { BaseTypeProps } from '../utils'

export type CloseParams = { url: string; index: number }

export interface ImagePreviewProps extends BaseTypeProps {
  visible?: boolean
  overlay?: boolean
  lazyload?: LazyImageType
  maxZoom?: number
  closeable?: boolean
  showIndicators?: boolean
  showIndex?: boolean
  indexRender?: ({
    index,
    len,
  }: {
    index: number
    len: number
  }) => React.ReactNode
  closeOnPopstate?: boolean
  overlayStyle?: React.CSSProperties
  beforeClose?: (active: string | number) => boolean | Promise<boolean>
  onClose?: (p?: CloseParams) => void
  onClosed?: () => void
  onChange?: (index: number) => void
  images?: string[]
  swipeDuration?: number
  startPosition?: number
  closeIcon?: React.ReactNode
  closeIconPosition?: PopupCloseIconPosition
  /** 只在点击关闭按钮时关闭ImagePreview组件 */
  closeOnlyClickCloseIcon?: boolean
  /** 弹出时的的父容器 */
  teleport?: HTMLElement | (() => HTMLElement)
}

export interface ImagePreviewItemProps {
  lazyload: LazyImageType
  image: string
  maxZoom: number
  onTap: () => void
  onZoomChange?: (zoom: number) => void
}

export type ImagePreviewStatic = {
  (props: ImagePreviewProps): React.ReactElement
  open: (OpenProps: Omit<ImagePreviewProps, 'visible'>) => () => void
}
